Value Property Example

This example demonstrates the Value property with Field and Property objects.

Sub ValueX()

    Dim dbsNorthwind As Database
    Dim rstEmployees As Recordset
    Dim fldLoop As Field
    Dim prpLoop As Property

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    Set rstEmployees = _
        dbsNorthwind.OpenRecordset("Employees")

    With rstEmployees
        Debug.Print "Field values in rstEmployees"
        ' Enumerate the Fields collection of the Employees 
        ' table.
        For Each fldLoop In .Fields
            Debug.Print "  " & fldLoop.Name & " = ";
            Select Case fldLoop.Type
                Case dbLongBinary
                    Debug.Print "[LongBinary]"
                Case dbMemo
                    Debug.Print "[Memo]"
                Case Else
                    ' Because Value is the default property of a 
                    ' Field object, the use of the actual keyword 
                    ' here is optional.
                    Debug.Print fldLoop.Value
            End Select
        Next fldLoop

        Debug.Print "Property values in rstEmployees"
        ' Enumerate the Properties collection of the 
        ' Recordset object.
        For Each prpLoop In .Properties
            On Error Resume Next
            ' Because Value is the default property of a 
            ' Property object, the use of the actual keyword 
            ' here is optional.
            If prpLoop <> "" Then Debug.Print "  " & _
                prpLoop.Name & " = " & prpLoop.Value
            On Error GoTo 0
        Next prpLoop

        .Close
    End With

    dbsNorthwind.Close

End Sub